package com.k2091.washcar.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.k2091.washcar.entity.Admin;
import com.k2091.washcar.entity.Cleaner;
import com.k2091.washcar.entity.FormInline;
import com.k2091.washcar.entity.Users;
import com.k2091.washcar.mapper.AdminMapper;
import com.k2091.washcar.mapper.CleanerMapper;
import com.k2091.washcar.mapper.UsersMapper;
import com.k2091.washcar.service.IAdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2021-06-01
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements IAdminService {


    @Autowired
    private UsersMapper usersMapper;

    @Autowired
    private CleanerMapper cleanerMapper;

    @Autowired
    private AdminMapper adminMapper;
    //管理员:增加用户
    @Override
    public int insertUser(Users users) {
        int r = usersMapper.insert(users);
        return r;
    }


    //管理员:修改用户信息
    @Override
    public int updateUser(Users users) {
        int r = usersMapper.update(users, new UpdateWrapper<Users>().eq("id", users.getId()));
        return r;
    }

    //管理员:增加洗车员
    @Override
    public int insertCleaner(Cleaner cleaner) {
        int r = cleanerMapper.insert(cleaner);
        return r;
    }

    //管理员:修改洗车员信息
    @Override
    public int updateCleaner(Cleaner cleaner) {
        int r = cleanerMapper.update(cleaner,new UpdateWrapper<Cleaner>().eq("id", cleaner.getId()) );
        return r;
    }

    //管理员:冻结用户
    @Override
    public int freezeUser(Long id) {
        Users user = new Users();
        user.setStatus(1);
        int r = usersMapper.update(user,new UpdateWrapper<Users>().eq("id", id));
        return r;
    }
    //管理员:冻结洗车员
    @Override
    public int freezeCleaner(Long id) {
        Cleaner cleaner = new Cleaner();
        cleaner.setStatus(1);
        int r = cleanerMapper.update(cleaner,new UpdateWrapper<Cleaner>().eq("id", id));
        return r;
    }

    @Override
    public List<Admin> selectAdmin(FormInline formInline) {
        return adminMapper.selectAdmin(formInline);
    }

    @Override
    public int deleteAdmin(Long id) {
        return adminMapper.deleteById(id);
    }

    @Override
    public int insertAdmin(Admin admin) {
        return adminMapper.insert(admin);
    }

    @Override
    public int upStatus(Long id, int status) {
        return adminMapper.upStatus(id, status);
    }

    @Override
    public Admin selectAdminById(Long id) {
        return adminMapper.selectById(id);
    }

    @Override
    public int upAdmin(Admin admin) {
        return adminMapper.updateById(admin);
    }

    @Override
    public Admin selectByNameAndPassword(String name, String password) {
        return adminMapper.selectByNameAndPassword(name,password);
    }
}
